/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests;

import javax.servlet.http.HttpSession;

/**
 * Instances of this class are used by the user interface when a user requests
 * to log out.
 *
 * @author Angel Sanadinov
 */
public class LogoutRequest extends RequestBean
{
    private HttpSession userSession; //the sessions associated with the user

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public LogoutRequest()
    {
        this.userSession = null;
    }

    /**
     * Constructs the request using the supplied data.
     *
     * @param userId the id of the user that want to log out
     * @param userSession the session associated with the user
     */
    public LogoutRequest(int userId, HttpSession userSession)
    {
        super.setRequestorId(userId);
        this.userSession = userSession;
    }

    /**
     * Sets the session associated with the user.
     *
     * @param userSession the user's session
     */
    public void setUserSession(HttpSession userSession)
    {
        this.userSession = userSession;
    }

    /**
     * Retrieves the session associated with the user.
     *
     * @return the user's session
     */
    public HttpSession getUserSession()
    {
        return userSession;
    }

    /**
     * Checks the validity of the object. <br><br>
     *
     * This object is valid only when all data supplied when constructing it is
     * valid.
     *
     * @return <code>true</code> if the object is valid or <code>false</code> otherwise
     */
    @Override
    public boolean isValid()
    {
        if(isRequestorIdValid() && userSession != null)
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return LogoutRequest.class.getSimpleName();
    }
}
